﻿using System;
using System.Collections;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.Utils;
using KPIS.DBM;


namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class RC_MoveRequestSubjects : System.Web.UI.UserControl
    {
        InquireBLL inquireBLL = new InquireBLL();
        private SsMng ssMng = new SsMng();
        private object _dataItem = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            txtNo.Attributes.Add("onkeypress", "return isNumberKey(event)");
            txtMax.Attributes.Add("onkeypress", "return isNumberKey(event)");

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblID.Text = DataBinder.Eval(DataItem, "subj_seq").ToString();
                    txtNo.Text = DataBinder.Eval(DataItem, "subj_no").ToString();
                    txtDescr.Text = DataBinder.Eval(DataItem, "descr").ToString();
                    txtMax.Text = DataBinder.Eval(DataItem, "max").ToString();
                    txtRemarks.Text = DataBinder.Eval(DataItem, "remarks").ToString();
                    DataTable dt = new DataTable();
                    //dt = db.ExecuteDataTable("select * from hrm_rc_move_requests where req_seq =" + lblID.Text);
                    //txtRetireDescr.Text = dt.Rows[0]["remarks"].ToString();
                    this.btnAddnew.Visible = false;
                    this.btnUpdate.Visible = true;
                }
                else 
                {
                    this.btnUpdate.Visible = false;
                    this.btnAddnew.Visible = true;
                }
            }

        }

 
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            try
            {
                bool dup = inquireBLL.ChkDuplicate(txtNo.Text);
                if (dup != true)
                    inquireBLL.Insert(txtNo.Text, txtDescr.Text, int.Parse(txtMax.Text), txtRemarks.Text, ssMng.EmpSeq);
            }
            catch(Exception ex)
            {

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                bool dup = inquireBLL.ChkDuplicate(txtNo.Text);
                if (dup != true)
                    inquireBLL.Update(int.Parse(lblID.Text), txtNo.Text, txtDescr.Text, int.Parse(txtMax.Text), txtRemarks.Text, ssMng.EmpSeq);
            }
            catch
            {

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

 
    }
}